package com.util.fileUpload.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.util.fileUpload.FileUploadProcessor;
import com.util.fileUpload.UploadFile;

@Component("mutileFileUpload")
public class MutileFileUpload implements FileUploadProcessor {

	@Autowired
	@Qualifier("defaultFileUpload")
	private FileUploadProcessor fileuploadProcessor;

	@SuppressWarnings("deprecation")
	public List<String> uploadFile(UploadFile... files) throws Exception {
		List<String> paths = new ArrayList<String>();
		for (UploadFile file : files) {

			final UploadFile fileObj = new UploadFile();
			fileObj.setBasePath(file.getBasePath());
			fileObj.setFile(file.getFile());
			fileObj.setFormate(file.getFormate());
			fileObj.setPath(file.getPath());

			int[] widths = file.getWidth();
			int[] heights = file.getHeight();
			for (int i = 0; i < file.getWidth().length; i++){
				int width = widths[i];
				int height = heights[i];
				
				fileObj.setWidth(new int[] { width });
				fileObj.setHeight(new int[] { height });
				List<String> tmp = fileuploadProcessor.uploadFile(fileObj);

				if (tmp == null || tmp.size() == 0) {
					
				}
				
				paths.add(tmp.get(0));
			}
		}

		return paths;
	}

	private final static RuntimeException exception = new UnsupportedOperationException("MutileFileUpload is not suppurt uploadOneFile Operation");

	public String uploadOneFile(UploadFile file) throws Exception {
		throw exception;
	}

}
